//
//  sySheZhiController.m
//  LazyCat
//
//  Created by rocky on 15/12/14.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "sySheZhiController.h"

@interface sySheZhiController ()<UITextFieldDelegate>

@property (nonatomic,strong) UITextField *textField1;

@end

@implementation sySheZhiController
- (void)backAction:(UIButton *)btn {
    [self.delegate back:self.textField1.text];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //添加导航与分割线
    [self initNav:@"使用设置" doBack:YES];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideKeyBoard:)];
    tap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tap];
    //第一行
    UIView *view1 = [[UIView alloc]init];
    view1.backgroundColor = [UIColor whiteColor];
    view1.frame = CGRectMake(0, 74, ScreenWidth, 50);
    [self.view addSubview:view1];
    UIView *lineV1 = [[UIView alloc]init];
    lineV1.alpha =0.2;
    lineV1.frame = CGRectMake(0, 0, ScreenWidth, 1);
    lineV1.backgroundColor = [UIColor lightGrayColor];
    [view1 addSubview:lineV1];
    UIView *lineV2 = [[UIView alloc]init];
    lineV2.alpha =0.2;
    lineV2.frame = CGRectMake(0, 49, ScreenWidth, 1);
    lineV2.backgroundColor = [UIColor lightGrayColor];
    [view1 addSubview:lineV2];
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 70, 50)];
    label1.text = @"订单金额";
    label1.textAlignment = NSTextAlignmentLeft;
    label1.font = [UIFont systemFontOfSize:14];
    label1.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [view1 addSubview:label1];
    self.textField1 = [[UITextField alloc]initWithFrame:CGRectMake(ScreenWidth-170, 0, 160, 50)];
    self.textField1.tag = 100;//tag值标示
    self.textField1.placeholder = @"未设置";
    self.textField1.keyboardType = UIKeyboardTypeNumberPad;
    self.textField1.textAlignment = NSTextAlignmentRight;
    self.textField1.font = [UIFont systemFontOfSize:14];
    self.textField1.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    [view1 addSubview:self.textField1];
    if ([self.isEdit isEqualToString:@"yes"]) {
        [self.textField1 addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }else {
        self.textField1.userInteractionEnabled = NO;
    }
    if ([self.isFrom isEqualToString:@"1"]) {
        float qian = [self.money floatValue];
        if (self.money.length == 0) {
            
        }else {
           self.textField1.text = [NSString stringWithFormat:@"%.0f",qian];
        }
    }else {
        float qian = [self.money floatValue];
        if (self.money.length == 0) {
            
        }else {
            self.textField1.text = [NSString stringWithFormat:@"%.0f",qian];
        }
    }
    //第二行
    UIView *view2 = [[UIView alloc]init];
    view2.backgroundColor = BackColor;
    view2.frame = CGRectMake(0, 124, ScreenWidth, 40);
    [self.view addSubview:view2];
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, ScreenWidth-30, 40)];
    label2.text = @"使用优惠券时需满足的订单金额，不包含配送服务费";
    label2.textAlignment = NSTextAlignmentLeft;
    label2.font = [UIFont systemFontOfSize:12];
    label2.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    [view2 addSubview:label2];
    //第三行
    UIView *view3 = [[UIView alloc]init];
    view3.backgroundColor = [UIColor whiteColor];
    view3.frame = CGRectMake(0, 164, ScreenWidth, 50);
    [self.view addSubview:view3];
    UIView *lineV3 = [[UIView alloc]init];
    lineV3.alpha =0.2;
    lineV3.frame = CGRectMake(0, 0, ScreenWidth, 1);
    lineV3.backgroundColor = [UIColor lightGrayColor];
    [view3 addSubview:lineV3];
    UIView *lineV4 = [[UIView alloc]init];
    lineV4.alpha =0.2;
    lineV4.frame = CGRectMake(0, 49, ScreenWidth, 1);
    lineV4.backgroundColor = [UIColor lightGrayColor];
    [view3 addSubview:lineV4];
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 90, 50)];
    label3.text = @"可使用商品";
    label3.textAlignment = NSTextAlignmentLeft;
    label3.font = [UIFont systemFontOfSize:14];
    label3.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [view3 addSubview:label3];
    UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-90, 0, 80, 50)];
    label4.text = @"全店通用";
    label4.textAlignment = NSTextAlignmentRight;
    label4.font = [UIFont systemFontOfSize:14];
    label4.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [view3 addSubview:label4];
}
-(void)hideKeyBoard:(UITapGestureRecognizer *)tap {//隐藏键盘
    [self.view endEditing:YES];
    [self.textField1 resignFirstResponder];
}
-(void)textFieldDidChange:(UITextField *)textField {//监听事件最多输入10个字符
    if (textField == self.textField1) {
        if (textField.text.length > 10) {
            textField.text = [textField.text substringToIndex:10];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
